package com.pengtu.web.human;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.entity.human.Overtime;
import com.pengtu.service.human.LeaveOvertimeManager;
import com.pengtu.utils.web.Struts2Utils;
import com.pengtu.web.BaseActionSupport;


/**
 * 加班记录
 * @author Administrator
 *
 */
@Results({@Result(name=BaseActionSupport.RELOAD,location="overtime.action",type="redirect")})
public class OvertimeAction extends BaseActionSupport<Overtime> {

	private static final long serialVersionUID = 1L;
	
	private String id;
	private Overtime overtime;
	private LeaveOvertimeManager leaveOvertimeManager;
	private Page<Overtime> page=new Page<Overtime>(10);
	
	@Override
	public Overtime getModel() {
		// TODO Auto-generated method stub
		return overtime;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		QueryFilter queryfilter=QueryFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		if(page.isOrderBySetted()){
			page.order(Page.ASC);
			page.orderBy("createDate");
		}
		page=leaveOvertimeManager.findPageOvertime(page, queryfilter);
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return INPUT;
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		leaveOvertimeManager.saveOvertime(overtime);
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		leaveOvertimeManager.deleteOvertime(id);
		return RELOAD;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		if(StringUtils.isNotEmpty(id)){
			overtime=leaveOvertimeManager.findPropertyOvertime("id", id);
		}else{
			overtime=new Overtime();
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Overtime getOvertime() {
		return overtime;
	}

	public void setOvertime(Overtime overtime) {
		this.overtime = overtime;
	}

	
//	public OvertimeManager getOvertimeManager() {
//		return overtimeManager;
//	}
//
//	public void setOvertimeManager(OvertimeManager overtimeManager) {
//		this.overtimeManager = overtimeManager;
//	}

	public Page<Overtime> getPage() {
		return page;
	}

	public LeaveOvertimeManager getLeaveOvertimeManager() {
		return leaveOvertimeManager;
	}

	public void setLeaveOvertimeManager(LeaveOvertimeManager leaveOvertimeManager) {
		this.leaveOvertimeManager = leaveOvertimeManager;
	}

	public void setPage(Page<Overtime> page) {
		this.page = page;
	}
	
	

}
